/**
 * Created by Eenie on 2016/12/11.
 */


/**
 * 获取今天的图片
 */

const delay = (ms) => {

    return new Promise((resolve, reject) => {
        setTimeout(() => {
            reject(new Error("fetch data timeout"));
        }, ms)
    })
}

const fetchWithTimeout = function (timeout, ...args) {
    return Promise.race([fetch(...args)], delay(timeout));
};

const GankActions = {
    API_PIC: 'http://gank.io/api/data/%E7%A6%8F%E5%88%A9/10/1',
    API_TIMEOUT: 10000,
    getTodayPic(){
        return fetchWithTimeout(this.API_TIMEOUT, this.API_PIC)
            .then(response => {
                response.json();
            });
    }
};


module.exports = GankActions;